<template>
  <div>
    <Button type="primary" @click="handleEdit">编辑</Button>
    <Poptip
      confirm
      title="确定删除该条记录吗？"
      @on-ok="handleDelete"
    >
        <Button type="error">删除</Button>
    </Poptip>
    <ModalBox ref="modalBox" :currPage="currPage" :articleId="articleId" type="edit" @on-update-list="updateList" />
  </div>
</template>

<script>
  import ModalBox from '../../pages/article/Modal';
  import request from '../../utils/request';
  import { Bus } from '../../utils/utils';
  export default {
    components: { ModalBox },
    props: ['articleId', 'currPage'],
    methods: {
      handleEdit() {
        this.$refs.modalBox.showModal();
      },
      handleDelete() {
        request({
          url: `/article/deleteArticle?articleId=${this.articleId}`,
          method: 'DELETE'
        }).then((result) => {
          const { code, message } = result;
          if (code === 200) {
            this.$Message.success(message);
            this.$emit('on-update-list', this.currPage);
          }
        }).catch((err) => {
          console.log(err);
        });
      },
      updateList(param) {
        this.$emit('on-update-list', param);
      }
    }
  }
</script>

<style scoped>

</style>
